package com.dxysun.mvc.controller;

import com.alibaba.fastjson.JSON;
import com.dxysun.mvc.repository.PushTokenRepo;
import com.dxysun.mvc.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dxy")
public class HelloController
{
	@Autowired
	private MyService myService;

	@Autowired
	private PushTokenRepo pushTokenRepo;

	@RequestMapping(value = "/first")
	public ModelAndView query(@RequestParam("teacher") String teacher)
	{
		System.out.println(myService.getAccountService().getName());
		Map<String, Object> model = new HashMap<>();
		model.put("teacher", teacher);
		model.put("data", teacher);
		model.put("token", "123456");
		return new ModelAndView("first", model);
	}

	@RequestMapping(value = "/query")
	@ResponseBody
	public String queryToken()
	{
		List<String> accountId = new ArrayList<>();
		accountId.add("12");
		return JSON.toJSONString(pushTokenRepo.queryAccountChannelMap(accountId));
	}
}
